package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类管理
 */
@Api(tags = "分类相关接口")
@RequestMapping("/admin/category")
@Slf4j
@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @ApiOperation("根据类型查询分类")
    @GetMapping("/list")
    public Result getByType(Integer type){
        log.info("根据类型查询分类:{}",type);
        List<Category> categories = categoryService.getByType(type);
        return Result.success(categories);
    }

    /**
     * 启动/禁用菜品分类
     * @param status
     * @param id
     * @return
     */
    @ApiOperation("启动/禁用菜品分类")
    @PostMapping("/status/{status}")
    public Result cateStatus(@PathVariable Integer status,Long id){
        log.info("启动/禁用菜品分类:{} {}",status,id);
        categoryService.cateStatus(status,id);
        return Result.success();
    }

    /**
     * 修改菜品分类
     * @param dto
     * @return
     */
    @ApiOperation("修改菜品分类")
    @PutMapping
    public Result modifyCate(@RequestBody CategoryDTO dto){
        log.info("修改分类：{}",dto);
        categoryService.modifyCate(dto);
        return Result.success();
    }

    /**
     * 根据id删除菜品分类
     * @param id
     * @return
     */
    @ApiOperation("根据id删除菜品分类")
    @DeleteMapping
    public Result deleteById(Long id){
        log.info("根据id删除菜品分类:{}",id);
        categoryService.deleteById(id);
        return Result.success();
    }

    /**
     * 分类分页查询
     * @param dto
     * @return
     */
    @ApiOperation("分类分页查询")
    @GetMapping("/page")
    public Result pagesGetCate(CategoryPageQueryDTO dto){
        log.info("分类分页查询:{}",dto);
        PageResult pageResult = categoryService.pagesGetCate(dto);
        return Result.success(pageResult);
    }

    /**
     * 新增套餐
     * @param dto
     * @return
     */
    @ApiOperation("新增套餐")
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO dto){
        log.info("新增套餐：{}",dto);
        categoryService.addCategory(dto);
        return Result.success();
    }
}
